package webshop;

import java.util.ArrayList;

public class Cart {

    private ArrayList<String[]> cart;

    public Cart() {
        cart = new ArrayList<String[]>();
    }

    public void changeProduct(String pid, int quantity) {
        boolean found = false;

        if (cart.isEmpty() && quantity != 0) {
            String[] product = {pid, "" + quantity};
            cart.add(product);
        } else {
            for (int i = 0; i < cart.size(); i++) {
                if (cart.get(i)[0].equals(pid) && !found) {
                    if (quantity == 0) {
                        cart.remove(i);
                    } else {
                        cart.get(i)[1] = "" + quantity;
                    }
                    found = true;
                }
            }
            if (!found && quantity != 0) {
                String[] product = {pid, "" + quantity};
                cart.add(product);
            }
        }
    }

    public ArrayList<String[]> getCart() {
        return cart;
    }
}
